<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="runId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
<!--				<el-table-column label="流水号" prop="id" width="150"></el-table-column>-->
<!--				<el-table-column label="流程标题" prop="flowTitle" width="150"></el-table-column>-->
				<el-table-column label="申请人" prop="userName" width="150"></el-table-column>
				<el-table-column label="申请人部门" prop="userDeptName" width="150"></el-table-column>
				<el-table-column label="审批人" prop="approverUserName" width="150"></el-table-column>
				<el-table-column label="审批人部门" prop="approverDeptName" width="150"></el-table-column>
				<el-table-column label="请假时间" prop="time" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="请假类型" prop="attendType" width="200">
					<template #default="scope">
						<el-tag v-if="scope.row.attendType=='A'" type="success">事假</el-tag>
						<el-tag v-else-if="scope.row.attendType=='B'" type="danger">婚假</el-tag>
						<el-tag v-else-if="scope.row.attendType=='C'" type="info">丧假</el-tag>
						<el-tag v-else-if="scope.row.attendType=='D'" type="warning">年假</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="请假事由" prop="leaveReason" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="申请状态" prop="typeStatus" width="150">
					<template #default="scope">
						{{ scope.row.typeStatus === undefined ? '--' : scope.row.typeStatus == 0 ? '审核中' : scope.row.typeStatus == 1 ? '通过' : '不通过' }}
					</template>
				</el-table-column>
<!--				<el-table-column label="操作" fixed="right" align="right" width="100">-->
<!--					<template #default="scope">-->
<!--						<el-button-group>-->
<!--							<el-button text type="primary" size="small" @click="readBpmDetails(scope.row,scope.$index)">查看</el-button>-->
<!--						</el-button-group>-->
<!--					</template>-->
<!--				</el-table-column>-->
			</scTable>
		</el-main>
	</el-container>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'

export default {
	name: 'My Attend Record',
	components: {
		scSelectFilter,
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave: false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "请假类型",
					key: "attendType",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "事假",
							value: "A"
						},
						{
							label: "婚假",
							value: "B"
						},
						{
							label: "丧假",
							value: "C"
						},
						{
							label: "年价",
							value: "D"
						}
					]
				}
			],
			apiObj: null,
			search: {
				attendType:'',
				date: '',
				// page: 1,
				// pageSize: 15
			}
		}
	},
	mounted() {
		this.initApiObj(); // 初始化时调用
	},
	methods: {
		// 初始化apiObj
		initApiObj() {
			const userInfo = this.$TOOL.data.get("USER_INFO");
			this.apiObj = {
				get: async (params) => {
					// 合并固定参数（userInfo.id）和动态参数（this.search）
					const mergedParams = {
						status:"5",
						option1: userInfo.id,
						...this.search,
						...params // 允许外部传入的params覆盖默认值
					};
					return await this.$API.office.attend.getTheApplicantSOutOfOfficeAttendanceList.get(mergedParams);
				}
			};
		},
		// 筛选条件变化时更新参数并刷新表格
		filterChange(data) {
			this.search.date = data.date;
			this.search.attendType = data.attendType;
			this.$refs.table.upData(this.search); // 触发表格重新加载
		},
		// filterChange(data) {
		// 	this.search.date = data.date;
		// 	this.$refs.table.upData(this.search)
		// },
		readBpmDetails(row, index) {
			this.$nextTick(() => {
				this.$router.replace({
					path: '/bpm/handle/read',
					query: {
						runId: row.runId
					}
				})
			})
		},
	}
}
</script>

<style>
</style>
